<template>
	<div class="wrap">
		<div :class="!btnFold ? 'inner over' : 'inner'" ref="divRef">
			<span class="content" ref="spanRef">
				<slot></slot>
			</span>
		</div>
		<span class="btn" v-if="textOver" @click="btnFold = !btnFold">
			{{
      btnFold ? "收起" : "查看全部"
    }}</span>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				textOver: false, //文本是否超出3行
				btnFold: false, //按钮默认显示展开
			};
		},
		created() {},
		mounted() {
			this.$nextTick(() => {
				let {
					spanRef,
					divRef
				} = this.$refs
				try {
					this.textOver = spanRef.offsetHeight > divRef.offsetHeight;
				} catch (e) {
					this.textOver = false
				}
			});
		},
		methods: {},
	};
</script>

<style scoped>
	.wrap {
		/* padding-bottom: 30px; */
	}

	.over {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 3;
		overflow: hidden;
	}

	.btn {
		font-size: 14px;
		color: rgba(224, 36, 36, 1);
		cursor: pointer;
		margin-top: 10px;
	}
</style>
